#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

uint64_t min_sum(vector<long> &v, int s, int t, vector<vector<uint64_t>> &recd)
{
        if(s == t || s + 1 == t){
                return recd[s][t] = 0;
        }

        if(recd[s][t] != -1){
                return recd[s][t];
        }
        uint64_t ans = INT64_MAX;
        for(int i = s + 1; i < t; i++){
                uint64_t sum = v[s] * v[t] * v[i];
                sum += min_sum(v, s, i, recd);
                sum += min_sum(v, i, t, recd);
                ans = min(ans, sum);
        }
        return recd[s][t] = ans;
}

int main()
{
        int n;
        cin >> n;
        vector<long> vertex(n, 0);
        for(int i = 0; i < n; i++){
                cin >> vertex[i];
        }

        vector<vector<uint64_t>> recd(n, vector<uint64_t>(n, -1));

        cout<<min_sum(vertex, 0, n - 1, recd)<<endl;
        return 0;
}